home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 13
/
QRZ Ham Radio Callsign Database - Volume 13.iso
/
unix
/
src
/
clook.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-23
|
2KB
|
154 lines
#include "cb.h"
#define SECTOR 512
clook(fp,call,rets)
FILE *fp;
char *call;
char *rets;
{
long pos;
long disp;
char str[256];
char tmp[32];
char kall[8];
char buf[1024];
char *p;
char *d;
int i;
int n;
int found;
int seeks;
long end;
fseek(fp,0,SEEK_END);
end = ftell(fp);
pos = end/2;
disp = pos;
p = kall;
while (*call)
*p++ = toupper(*call++);
*p = '\0';
seeks = 0;
found = 0;
while (!found)
{
memset(buf,0,sizeof(buf));
memset(str,0,sizeof(str));
memset(tmp,0,sizeof(tmp));
seeks++;
fseek(fp,pos,SEEK_SET);
fread(buf,SECTOR,1,fp);
p = buf;
/* move to next whole entry */
while (*p && (*p != '\n'))
p++;
p++;
if (!*p)
break; /* end of file */
d = str; /* get the whole entry */
while (*p && (*p != '\n'))
*d++ = *p++;
d = tmp;
p = str; /* get just the call */
while (*p != DELIMITER)
*d++ = *p++;
/*
n = callcmp(tmp,kall);
*/
n = strcmp(tmp,kall);
if (n == 0)
{
strcpy(rets,str);
found++;
break;
}
if (!disp)
{
break;
}
disp = disp >> 1;
if (n > 0)
pos -= disp;
else
pos += disp;
}
/*
if (found)
printf("Found in %d seeks\n\n",seeks);
*/
return found;
}
callcmp(str,call)
char *str;
char *call;
{
char s1[8];
char c1[8];
char *ps;
char *pc;
char *ds;
char *dc;
int n;
/* compare the AB#CDE sequence */
strcpy(s1,str);
strcpy(c1,call);
ps = s1;
ps++;
if (!isdigit(*ps))
ps++; /* point to #CDE */
ds = ps;
pc = c1;
pc++;
if (!isdigit(*pc))
pc++; /* point to #CDE */
dc = pc;
if (n = strcmp(ps,pc))
return(n); /* unequal suffixes */
/* suffixes are equal - check prefixes AB */
*ds = '\0';
*dc = '\0';
if ((int)strlen(s1) == (int)strlen(c1))
return strcmp(s1,c1);
/* AB vs A */
if (s1[1])
return 1;
else /* A vs AB */
return -1;
}